package com.ycp.erp.role.ui.binder;

import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.one.common.view.multitytype.adapter.BaseItemBinder;
import com.one.common.view.multitytype.adapter.BaseViewHolderMulti;
import com.ycp.erp.R;
import com.ycp.erp.role.model.bean.Permissions;
import com.ycp.erp.role.ui.view.SelectInter;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

/**
 * Class Des:
 * Created by bjh on 2021/9/14.
 */
public class PermissionTBinder extends BaseItemBinder<Permissions.PermissionsT> {

    private  SelectInter listener;
    @BindView(R.id.ivSelect)
    ImageView ivSelect;
    @BindView(R.id.tvItem)
    TextView tvItem;
    @BindView(R.id.ivArrowDown)
    ImageView ivArrowDown;
    @BindView(R.id.rlItem)
    RelativeLayout rlItem;
    @BindView(R.id.rcv)
    RecyclerView rcv;

    public PermissionTBinder(SelectInter listener) {
        super(R.layout.item_permission);
        this.listener=listener;
    }

    @Override
    protected void bindView(@NonNull BaseViewHolderMulti holder, @NonNull Permissions.PermissionsT item) {
        ImageView ivSelect = holder.getView(R.id.ivSelect);
        TextView tvItem = holder.getView(R.id.tvItem);
        ImageView ivArrowDown = holder.getView(R.id.ivArrowDown);
        ivArrowDown.setVisibility(View.GONE);
        if (item.isSelect()) {
            ivSelect.setImageResource(R.mipmap.ic_selected_circle);
        } else {
            ivSelect.setImageResource(R.mipmap.ic_unselected_circle);
        }
        ivSelect.setOnClickListener(v -> {
            item.setSelect(!item.isSelect());
            if (item.isSelect()) {
                ivSelect.setImageResource(R.mipmap.ic_selected_circle);
            } else {
                ivSelect.setImageResource(R.mipmap.ic_unselected_circle);
            }
            if (item.isSelect()&&listener!=null){
                listener.isSelect();
            }
        });
        tvItem.setText(item.getThirdName());

    }
}
